<template>
	<view>
		<view class="utit">
			<image class="bcg" src="../../static/bcg.png" mode=""></image>
			<view class="texts">您好，请登录~</view>
		</view>
		<view class="uinput">
			<view class="uinput_it">
				<view class="uinput_flex">
					<image class="imgs" src="../../static/icon1.png" mode=""></image>
					<view class="ts">账号</view>
				</view>
				<view class="inputs">
					<input type="text" v-model="params.username" placeholder="请输入账号" placeholder-class="phsy" />
				</view>
			</view>

			<view class="uinput_it">
				<view class="uinput_flex">
					<image class="imgs" src="../../static/icon2.png" mode=""></image>
					<view class="ts">密码</view>
				</view>
				<view class="inputs" style="display: flex;align-items: center;">
					<input v-model="params.password" :password="showPwd" placeholder="请输入密码" placeholder-class="phsy" />
					<uni-icons :type="showPwd?'eye-slash':'eye'" size="24" @click="changeType"></uni-icons>
				</view>
			</view>

			<view class="uinput_it">
				<view class="uinput_flex">
					<image class="imgs" src="../../static/icon3.png" mode=""></image>
					<view class="ts">验证码</view>
				</view>
				<view class="inputs" style="display: flex;align-items: center;">
					<input v-model="params.code" placeholder="请输入验证码" placeholder-class="phsy" />
					<image class="eimage" :src="codeimg" mode="" @click="getcode()"></image>
				</view>
			</view>

		</view>
		<view class="mim">
			<switch color="#316FFC" class="sw" :checked='isshow' type='checkbox' @change="switch2Change">
				记住密码
			</switch>
		</view>
		<view class="btn" :class="isall?'on':''" @click="goindex">
			登录
		</view>
	</view>
</template>

<script>
	import {
		getlogin,
		getText,
		getUserinfo
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				showPwd: true,
				isshow: true,
				params: {
					username: '',
					password: '',
					code: '',
					uuid: ''
				},
				codeimg: ''
			}
		},
		computed: {
			isall() {
				return this.params.username == '' || this.params.password == '' || this.params.code == ''
			}
		},
		onLoad() {
			console.log(this.isall);
			this.getcode()
			if (uni.getStorageSync('username')) {
				this.params.username = uni.getStorageSync('username')
				this.params.password = uni.getStorageSync('password')
			}
		},
		methods: {
			getcode() {
				getText().then(res => {
					this.codeimg = "data:image/gif;base64," + res.img;
					this.params.uuid = res.uuid
				})
			},
			changeType() {
				this.showPwd = !this.showPwd
			},
			switch2Change(e) {
				console.log(e);
			},
			goindex() {
				// if (this.params.account == '') {
				// 	uni.showToast({
				// 		title: '请输入账号',
				// 		duration: 2000,
				// 		mask: false,
				// 		icon: "none"
				// 	})
				// } else if(this.params.password == '') {
				// 	uni.showToast({
				// 		title: '请输入密码',
				// 		duration: 2000,
				// 		mask: false,
				// 		icon: "none"
				// 	})
				// }else if(this.params.code == ''){
				// 	uni.showToast({
				// 		title: '请输入验证码',
				// 		duration: 2000,
				// 		mask: false,
				// 		icon: "none"
				// 	})
				// }
				if (!this.isall) {
					uni.showLoading({
						title: '登录中...',
						mask: true
					})
					getlogin(this.params).then(res => {
						if (res.code == 200) {
							if (this.isshow) {
								uni.setStorageSync('username', this.params.username)
								uni.setStorageSync('password', this.params.password)
								uni.setStorageSync('token', res.token)
							} else {
								uni.removeStorageSync('username')
								uni.removeStorageSync('password')
							}
							uni.hideLoading()
							uni.reLaunch({
								url: '/pages/index/index'
							})
						}
					})
				}


			}
		}
	}
</script>

<style lang="scss">
	.utit {
		position: relative;
		height: 580rpx;

		.bcg {
			width: 100%;
			height: 580rpx;
		}

		.texts {
			position: absolute;
			font-family: PingFang SC;
			font-weight: 800;
			font-size: 56rpx;
			color: #000000;
			left: 61rpx;
			bottom: 247rpx;
		}
	}

	.uinput {
		width: 630rpx;
		margin-top: -180rpx;
		z-index: 99;
		position: relative;
		left: 65rpx;

		.uinput_it {
			border-bottom: 1px solid #DFDFDF;
			margin-top: 72rpx;

			.uinput_flex {
				display: flex;
				align-items: center;

				.imgs {
					width: 40rpx;
					height: 40rpx;
					margin-right: 14rpx;
				}

				.ts {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #000000;
				}
			}

			.inputs {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				padding: 34rpx 0rpx 19rpx 0rpx;

				input {
					flex: 1;
				}

				.eimage {
					width: 192rpx;
					height: 82rpx;
				}
			}
		}

	}

	.mim {
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #C2C2C2;
		margin: 40rpx 60rpx;

		.sw {
			display: flex;
			align-items: center;
		}
	}

	.phsy {
		color: #C2C2C2 !important;
	}

	.btn {
		width: 630rpx;
		height: 90rpx;
		background: #316FFC;
		border-radius: 20rpx;
		margin: 105rpx auto;
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 32rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 90rpx;
	}

	.on {
		background: #316FFC;
		opacity: 0.5;
	}
</style>